{template header}

<script type="text/javascript">
	function sendMessage(){
		var content = $("#content").val();

		if('' == content){
			alert("发送内容不能为空");
			return false;
		}
        
		$.ajax({    
		    url:'?c=admin&a=SendPuNiuMessage',// 跳转到 action    
		    data:{    
	             content : content,    
	             targetId : {$targetId},   
                 //is_all : $("#is_all").is(":checked")
		    },    
		    type:'post',    
		    cache:false,    
		    dataType:'json',    
		    success:function(data) {    
		         if("1" == data.result){
		         	alert("发送成功");
		         	$("#content").val('');
		         	window.location.href = "";
		         }
		    },    
		    error : function() {    
		          alert("发送失败");    
		    }    
		});
	}
</script>
<!-- <script src="http://res.websdk.rongcloud.cn/RongIMClient-0.9.9.min.js"></script>
<script type="text/javascript" src="http://res.websdk.rongcloud.cn/RongIMClient.emoji-0.9.2.min.js"></script>
<script type="text/javascript">
	
	// $(function(){

	// 	var emojiObjectList = RongIMClient.Expression.getAllExpression(127,0);
	// 	  //从下标为0的位置检索64个表情对象,startIndex与count只和最大为128，因为表情对象最多为128个。
	// 	  for(var i=0,item;item=emojiObjectList[i++];){
	// 	  		console.log(item.tag);
	// 	     	//console.log(item.englishName,item.chineseName,item.img,item.tag);
	// 	     //依次打印表情元素
	// 	  }
	// });
</script> -->
<!-- <script src="http://res.websdk.rongcloud.cn/RongIMClient-0.9.9.min.js"></script>
<script type="text/javascript">
$(function(){
	//初始化
	RongIMClient.init("p5tvi9dst2jj4");

	//获取token
	$.ajax({
		type:"post",
		url:"?c=admin&a=GetUserImToken",
		data:{
			"targetId":{$targetId}
		},
		dataType:"json"
	}).done(function(data){
		data.im_token = "g90dnY6X1u0lptrnwAHGIJILLVV1R1BU8cNEJUafULQA9H07DZS9F2VnaxaMXFFyyJVUsgaFlXrmwv+x4EfMdA==";
		console.log(data.im_token);
		if(data.im_token){

			RongIMClient.connect(data.im_token, {
                onSuccess: function (x) {
                    console.log("connected，userid＝" + x);

                    //链接成功之后同步会话列表
                    RongIMClient.getInstance().syncConversationList({
                        onSuccess: function () {
                            //同步会话列表
                            setTimeout(function () {
                                list = RongIMClient.getInstance().getConversationList();
                                console.log(list);
                                
                            }, 1000);
                        }, onError: function () {
                        	console.log("ddd");
                        }
                    });
                },
                onError: function (c) {
                    var info = '';
                    switch (c) {
                        case RongIMClient.callback.ErrorCode.TIMEOUT:
                            info = '超时';
                            break;
                        case RongIMClient.callback.ErrorCode.UNKNOWN_ERROR:
                            info = '未知错误';
                            break;
                        case RongIMClient.ConnectErrorStatus.UNACCEPTABLE_PROTOCOL_VERSION:
                            info = '不可接受的协议版本';
                            break;
                        case RongIMClient.ConnectErrorStatus.IDENTIFIER_REJECTED:
                            info = 'appkey不正确';
                            break;
                        case RongIMClient.ConnectErrorStatus.SERVER_UNAVAILABLE:
                            info = '服务器不可用';
                            break;
                        case RongIMClient.ConnectErrorStatus.TOKEN_INCORRECT:
                            info = 'token无效';
                            break;
                        case RongIMClient.ConnectErrorStatus.NOT_AUTHORIZED:
                            info = '未认证';
                            break;
                        case RongIMClient.ConnectErrorStatus.REDIRECT:
                            info = '重新获取导航';
                            break;
                        case RongIMClient.ConnectErrorStatus.PACKAGE_ERROR:
                            info = '包名错误';
                            break;
                        case RongIMClient.ConnectErrorStatus.APP_BLOCK_OR_DELETE:
                            info = '应用已被封禁或已被删除';
                            break;
                        case RongIMClient.ConnectErrorStatus.BLOCK:
                            info = '用户被封禁';
                            break;
                        case RongIMClient.ConnectErrorStatus.TOKEN_EXPIRE:
                            info = 'token已过期';
                            break;
                        case RongIMClient.ConnectErrorStatus.DEVICE_ERROR:
                            info = '设备号错误';
                            break;
                    }
                    console.log("失败:" + info);
                }
            });
		}else{
			console.log("获取token失败");
		}

	}).fail(function(){

	});


	//链接状态监听器
    RongIMClient.setConnectionStatusListener({
        onChanged: function (status) {
            switch (status) {
                //链接成功
                case RongIMClient.ConnectionStatus.CONNECTED:
                    console.log('链接成功');
                    break;
                //正在链接
                case RongIMClient.ConnectionStatus.CONNECTING:
                    console.log('正在链接');
                    break;
                //重新链接
                case RongIMClient.ConnectionStatus.RECONNECT:
                    console.log('重新链接');
                    break;
                //其他设备登陆
                case RongIMClient.ConnectionStatus.OTHER_DEVICE_LOGIN:
                //连接关闭
                case RongIMClient.ConnectionStatus.CLOSURE:
                //未知错误
                case RongIMClient.ConnectionStatus.UNKNOWN_ERROR:
                //登出
                case RongIMClient.ConnectionStatus.LOGOUT:
                //用户已被封禁
                case RongIMClient.ConnectionStatus.BLOCK:
                    //location.href = "/WebIMDemo/login.html";
                    break;
            }
        }
    });


	RongIMClient.getInstance().setOnReceiveMessageListener({
        onReceived: function (data) {
            //if (hasSound) {
                //audio.play();
            //}
            //如果接收的消息为通知类型或者状态类型的消息，什么都不执行
            if (data instanceof RongIMClient.NotificationMessage || data instanceof RongIMClient.StatusMessage) {
                return;
            }

            //设置会话名称
            var item = RongIMClient.getInstance().getConversation(data.getConversationType(), data.getTargetId());

            console.log(item);

                switch(item.getConversationType()){
                    case RongIMClient.ConversationType.PRIVATE:
                        RongIMClient.getInstance().getUserInfo(item.getTargetId(),{
                            onSuccess: function (info) {
                                 item.setConversationTitle(info.getUserName());
                            },
                            onError: function () {
                                 item.setConversationTitle("陌生人Id：" + item.getTargetId());
                            }
                        });

                        console.log(item.getLatestMessage().getContent());
                        privateUnReadCount = RongIMClient.getInstance().getUnreadCount(RongIMClient.ConversationType.PRIVATE,data.getTargetId());
                        console.log(privateUnReadCount);

                        break;
                    default :
                        item.setConversationTitle('该会话类型未解析key: "value", ' + data.getConversationType()+data.getTargetId());
                        break;
                }
                $("#historyMessage").append($("<li />").append("会话标题:" + item.getConversationTitle() + ";<br />")
                                                        .append("会话类型值:" + item.getConversationType().valueOf() + ";<br />")
                                                        .append("目标ID:" + item.getTargetId() + ";<br />")
                                                        .append("消息的最后时间戳:" + item.getLatestTime())  );
        }
    });


});
	


	

</script> -->
<div class="bs-docs-example" style="clear:both;">

	<!-- <div>
		<div>当前用户:&nbsp;&nbsp;&nbsp;<img width="30" height="30" src="{$targetHeader}">&nbsp;&nbsp;&nbsp;{$targetName}</div>
	</div> -->
	<form class="form-horizontal"  method="post">

		<div class="control-group">
		    <label class="control-label" for="inputTiltle">当前用户:</label>
		      <div class="control-group">
		        <div class="controls">
		        	<img width="30" height="30" src="{$targetHeader}">&nbsp;&nbsp;&nbsp;{$targetName}
		        </div>

		    </div>

	  	</div>

        <!-- <div class="control-group">
            <label class="control-label" for="inputTiltle">是否发送给全部用户:</label>
              <div class="control-group">
                <div class="controls">
                    <input type="checkbox" id="is_all" >
                </div>

            </div>

        </div> -->

                    


		<div class="control-group">
		    <label class="control-label" for="inputTiltle">要发送的内容:</label>
		      <div class="control-group">
		        <div class="controls">
		        	<input type="hidden" name="targetId" value="{$targetId}">
		          <textarea name="content" id="content" placeholder="请输入要发送的消息内容" style="min-width:80%; min-height:200x;"></textarea>
		        </div>
		    </div>

		    <div class="controls">
		        <button type="button" class="btn" onclick="sendMessage()" >发送</button>
		    </div>
	  	</div>
		  
	</form>


	<!-- <div>会话记录
		<ol id="historyMessage">

		</ol>
	</div> -->

	

    <table class="table table-striped">
        <thead>
            <tr>
                <th width="10">ID</th>
                <th width="100">消息来源</th>
                <th width="50">内容</th>
                <th width="100">发送时间</th>
            </tr>
        </thead>
        <tbody>
            {loop $data $k $item}
            <tr>
                <td>{$item['id']}</td>
                <td>{if $item['stype'] == 'from'}对方{else}自己{/if}</td>
                <td style="max-width: 40px;word-wrap:break-word">{if $item['objectName'] == 'RC:ImgMsg'}<img width="30" height="30"  src="{$item['content']}"><a href="{$item['content']}" target="_blank">查看</a>{else}{$item['content']}{/if}</td>
                <td>{eval echo date('Y-m-d H:i:s', $item['time'])}</td>
            </tr>
            {/loop}
        </tbody>
    </table>
</div>
<div class="pagination">
    <ul>
        {$pageStr}
    </ul>
</div>

{template footer}
